﻿using DataAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace KhoaLuan.MainSys.Controls
{
    public partial class ctArticleCategory : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public void LoadData(string titlebox, int orgid, int postcatid)
        {
            lbTitleBox.InnerHtml = titlebox;
            var proxy = new tbPosts_Proxy();
            repTopNotice.ItemDataBound += repTopNotice_ItemDataBound;
            repTopNotice.DataSource = proxy.SelectNewsByOrgCategory(orgid, postcatid).Where(x => x.Active == 1);
            repTopNotice.DataBind();
        }

        void repTopNotice_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            try
            {
                var tbPosts = e.Item.DataItem as tbPosts;
                var divdate = e.Item.FindControl("lbDate") as System.Web.UI.HtmlControls.HtmlGenericControl;
                if (tbPosts.UpdatedDate != null)
                    divdate.InnerHtml = tbPosts.UpdatedDate.Value.ToString("(dd/MM/yyyy)");
                else
                    divdate.InnerHtml = tbPosts.CreatedDate.ToString("(dd/MM/yyyy)");
            }
            catch (Exception)
            {
            }
        }
    }
}